'use strict';

var mongoose = require('mongoose');
var modelPlugin = require("../model.plugin");
var Schema = mongoose.Schema;
var ObjectId  = Schema.ObjectId;

var robruleSchema = new Schema({
  // name + config.rulePrefix + openId must unique;
  name: {type: String},
  pattern: {type: String},
  handler: {type: String},
  openId: {type: String},
  userId: {type: ObjectId, ref: 'User'},
  description: {type: String},
  // {0: unable, 1: ok, 2: disable}
  state: {type: Number, default: 0},
  // {0: user, 1: all, 2: disable}
  mode: {type: Number, default: 0},
  remark: {type: String},

  createdAt: {type: Date, default: Date.now},
  createdBy: {type: ObjectId, ref: 'User'},
  updatedAt: {type: Date, default: Date.now},
  updatedBy: {type: ObjectId, ref: 'User'}
});

// robruleSchema.plugin(modelPlugin);
// robruleSchema.index({name: 1});

mongoose.model('Robrule', robruleSchema);
